package API.Stream.EndMethod;

import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Collectors;

public class ToArrayAndCollect {
    public static void main(String[] args) {
        String[] arr = new String[]{"Jack-10", "Alic-25", "Nick-40", "Black-90"};
        System.out.println(Arrays.stream(arr).toArray().toString());
        System.out.println(Arrays.stream(arr).collect(Collectors.toList()));
        Arrays.stream(arr).collect(Collectors.toMap(
                new Function<String, String>() {
                    @Override
                    public String apply(String s) {
                        return s.split("-")[0];
                    }
                },
                new Function<String, String>() {
                    @Override
                    public String apply(String s) {
                        return s.split("-")[1];
                    }
                }
        )).forEach((k, v) -> System.out.println(k + "=" + v));
        Arrays.stream(arr).collect(Collectors.toMap(
                s -> s.split("-")[0],
                s -> Integer.parseInt(s.split("-")[1])
        )).forEach((k, v) -> System.out.println(k + "=" + v));
    }
}
